package com.haizhi.crm.sys.configure.dao;

import com.haizhi.crm.sys.configure.model.UserModuleDo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by caochao on 2018/05/31.
 */
@Repository
public interface UserModuleDao extends JpaRepository<UserModuleDo, Long> {
    List<UserModuleDo> findByUserId(Long userId);

    List<UserModuleDo> findByUserIdAndModuleId(Long userId, Long moduleId);

    @Query(value = "delete from UserModuleDo where userId =:userId and moduleId=:moduleId" )
    @Modifying
    void deleteBy(@Param("userId" ) Long userId, @Param("moduleId" ) Long moduleId);


    @Query(value = "SELECT moduleId from UserModuleDo where userId =:userId" )
    List<Long> findModuleIdsBy(@Param("userId" ) Long userId);

}
